﻿using Scap.Data;
using Scap.Info;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Scap.Core
{
    class ConfigurationHandler
    {

        internal int GetMonitorInterval()
        {
            ScapData db = new ScapData();
            var items = from d in db.MonitorConfiguration select d;
            ScapMonitorConfiguration config = null;

            foreach (ScapMonitorConfiguration c in items)
            {
                config = c;
                break;
            }

            if (config != null)
                return config.Interval;
            else
                return 30;

        }

        internal void SetNotificationDestinataryList(System.Net.Mail.MailMessage mail)
        {
            ScapData db = new ScapData();

            //var coll = from d in db.Notifications select d;

            //foreach (ScapNotification n in coll)
            //    if (!string.IsNullOrEmpty(n.Email))
            //        mail.To.Add(n.Email);
        }

        internal ScapEmailConfiguration GetEmailConfig()
        {
            ScapData db = new ScapData();
            var items = from d in db.EmailConfiguration select d;
            ScapEmailConfiguration config = null;

            foreach (ScapEmailConfiguration c in items)
            {
                config = c;
                break;
            }

            if (config != null)
                return config;
            else
                throw new ApplicationException("Email configuration not defined");
        }
    }
}
